
package com.mego.megoandroid.utils;


import com.mego.megoandroid.model.NoteInfo;

import org.json.JSONException;
import org.json.JSONObject;
import org.xutils.common.Callback;
import org.xutils.http.RequestParams;
import org.xutils.x;

//只是提供Demo
//不需要单独写这个类
public class HttpXutils {

    public static final String URL_BASE = "https://by.megowx.com/app/index.php?i=3&c=entry&m=ewei_shopv2&do=mobile";

    //示例代码>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    // GET
    public static void test() {

    }

    // POST
    //1. API输出的参数， 使用GsonFormat生成NoteInfo
    //2. NoteInfo添加parseJson；
    public static void phalapi_post() {
        JSONObject js_request = new JSONObject();//服务器需要传参的json对象
        try {
            js_request.put("goods", "fwefwef");
        } catch (JSONException e) {
            e.printStackTrace();
        }

        String url = "http://wapi.megowx.com/public/?s=User.Index";
        RequestParams requestParams = new RequestParams(url);
        requestParams.setAsJsonContent(true);
        requestParams.setBodyContent(js_request.toString());
        x.http().post(requestParams, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                try {
                    NoteInfo n = NoteInfo.parseJson(result);
                    System.out.println(n.getData().getGoods());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                System.out.println("errot");
            }

            @Override
            public void onCancelled(CancelledException cex) {
            }
            @Override
            public void onFinished() {
            }
        });
    }
    //示例代码>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

}